package net.jkdmanager.agent.services.plugins;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.jkdmanager.agent.services.configuration.AgentConfigurationService;
import net.jkdmanager.common.api.model.Application;
import net.jkdmanager.common.api.plugins.DirectorI;
import net.jkdmanager.common.api.plugins.DistributorI;
import net.jkdmanager.common.api.plugins.RunnerI;
import net.jkdmanager.common.services.plugins.PluginRegistryService;

@Service
public class AgentPluginServiceImpl implements AgentPluginService {

	@Autowired
	private AgentConfigurationService agentConfigurationService;
	
	@Autowired
	private PluginRegistryService pluginRegistryService;
	
	public DistributorI getDistributor(long appId) {
		Application app = agentConfigurationService.getApplication(appId);
		return pluginRegistryService.getPlugin(DistributorI.class, app.getDistributor().getType());
	}

	public DirectorI getDirector(long appId) {
		Application app = agentConfigurationService.getApplication(appId);
		return pluginRegistryService.getPlugin(DirectorI.class, app.getDistributor().getType());
	}

	public RunnerI getRunner(long appId) {
		Application app = agentConfigurationService.getApplication(appId);
		return pluginRegistryService.getPlugin(RunnerI.class, app.getDistributor().getType());
	}

}
